﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

using mvcForum.Core;
using mvcForum.Core.Interfaces.Data;

namespace mvcForum.DataProvider.EntityFramework.Repositories {

	public class BoardRepository : Repository<Board>, IBoardRepository {

		public BoardRepository(DbContext context) : base(context) { }

		/// <summary>
		/// Read one board that match the specification, including categories.
		/// </summary>
		/// <param name="spec"></param>
		/// <returns></returns>
		public Board ReadOneOptimized(ISpecification<Board> spec) {
			return this.ReadManyOptimized(spec).FirstOrDefault();
		}

		public IEnumerable<Board> ReadManyOptimized(ISpecification<Board> spec) {
			return this.set.Include(b => b.Categories).Where(spec.IsSatisfied);
		}
	}
}